package cn.javass.dp.strategy.example3;

/**
 * 上下文对象，通常会持有一个具体的策略对象(优点：strategy不需要改动接口 缺点：不同策略的参数统一维护在上下文里面)
 */
public class Context {

	/**
	 * 应被支付工资的人员，简单点，用姓名来代替
	 */
	private String userName = null;
	/**
	 * 应被支付的工资的金额
	 */
	private double money = 0.0;

	/**
	 * 银行帐号
	 */
	private String account = null;

	public Context(String userName, double money, String account, Strategy strategy) {
		this.userName = userName;
		this.money = money;
		this.account = account;
		this.strategy = strategy;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public Strategy getStrategy() {
		return strategy;
	}

	public void setStrategy(Strategy strategy) {
		this.strategy = strategy;
	}

	/**
	 * 持有一个具体的策略对象
	 */
	private Strategy strategy;
	/**
	 * 构造方法，传入一个具体的策略对象
	 * @param aStrategy 具体的策略对象
	 */
	public Context(Strategy aStrategy) {
		this.strategy = aStrategy;
	}
	/**
	 * 上下文对客户端提供的操作接口，可以有参数和返回值
	 */
	public void contextInterface() {
		//通常会转调具体的策略对象进行算法运算
		strategy.algorithmInterface(this);
	}

}

